// Copyright 2011 George Cook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


#import "InjectivePropertyValueDescription.h"
#import "InjectiveContainer.h"
#import "InjectiveMacros.h"

@implementation InjectivePropertyValueDescription
@synthesize propertyValueText, type;


#pragma mark -
#pragma mark init and dealloc

- (void)dealloc
{
	[propertyValueText release], propertyValueText = nil;
	[type release], type = nil;
	[super dealloc];
}

- (id)initWithPropertyValue:(NSString *) aValue withType:(NSString *) aType
{
	if (self = [super init]) {
		propertyValueText = [aValue retain];
		type = [aType retain];
	}
	return self;
}

- (id)realValueUsingContainer:(InjectiveContainer *)container
{
	id value;
	if ([type isEqualToString:@"String"]) {
		value = propertyValueText;
	}
	else if ([type isEqualToString:@"Integer"])
	{
		value = INJNINT([propertyValueText intValue]);
	}
	else if ([type isEqualToString:@"Float"])
	{
		value = INJNFLOAT([propertyValueText floatValue]);
	}
	else if ([type isEqualToString:@"Bool"])
	{
		value = INJNBOOL([propertyValueText boolValue]);
	}
	return value;
}

- (NSString *)description
{
	return [[super description] stringByAppendingFormat:@"propertyValueText: %@ type %@",
			self.propertyValueText, self.type];
}

@end
